﻿package mvc_view
{
	import flash.display.*;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	public class UsersView extends View
	{
		private var _container:Sprite;
		private var _backgroundShape:Shape;
		
		// user avatar pic
		private var _loader:Loader;
		private var _bmpImage:Bitmap;
		
		// user information
		private var _name:TextField;
		private var _email:TextField;
		private var _dob:TextField;
		private var _city:TextField;
		private var _country:TextField;
		private var _gender:TextField;
		
		public function UsersView(container:MovieClip)
		{
			_container = container;
			_container.buttonMode = true;
			//_name = name;
			
			//_backgroundShape = Shape(_container.getChildAt(0));
			_bmpImage = new Bitmap();
			
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
			
			_container.addChild(_bmpImage);
			_container.addChild(_loader);
		}
		
		override public function update(event:Event = null):void
		{
			// load avatar image with url from xml file
			_loader.load(new URLRequest(model.currentImage));
			
			// DEBUG: output data from model
			trace("Model.currentTitle = " + model.currentTitle);
			
			// update user data from model
			//_name.text = model.currentTitle;
		}
		
		private function imageLoaded(event:Event):void
		{
			_container.addChild(_loader);
		}
	}
}